﻿#define NO_RESTRICT

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Configuration;

namespace Feelingme.ShareMSDN
{
    public partial class MSDNEntities
    {
        public static MSDNEntities Create()
        {
            return new MSDNEntities(
                WebConfigurationManager.ConnectionStrings["MSDNEntities"].ConnectionString);
        }
    }

    public partial class ProductType
    {
        public long CategoryId { get { return this.ID; } }
        public string CategoryName { get { return this.ProductType1; } }
        public IEnumerable<ProductName> Families { get; set; }
    }

    public partial class ProductName
    {
        public long FamilyId { get { return this.ID; } }
        public string FamilyName { get { return this.ProductName1; } }
        public IEnumerable<Item> Ships { get; set; }
    }

    public partial class Item
    {
        public long ShipId { get { return this.ID; } }
        public string ShipName { get { return this.DetailsName; } }
        public string eMuleHash { get { return this.FileID; } }

        //
        public string r00 { get { return Availabilty ? "on" : "off"; } }
#if NO_RESTRICT
        public string r01 { get { return Availabilty ? "href=\"" + ed2k + "\" target=\"_blank\"" : "disabled style=\"color: #999999;\""; } }
#else
        public string r01 { get { return IsAvailable ? "onclick=\"alert('beta version')\" href=\"javascript:void(0)\"" : "disabled style=\"color: #999999;\""; } }
#endif
        //

        public bool Availabilty
        {
            get { return !String.IsNullOrEmpty(eMuleHash); }
        }
        public string CRC
        {
            get { return this.ISOCRC; }
        }
        public string ed2k
        {
            get
            {
#if NO_RESTRICT
               return String.Format(CultureInfo.InvariantCulture, "ed2k://|file|{0}|{1}|{2}|/",
                    this.FileName, this.FileSize, this.eMuleHash);
#else
                return null;
#endif
            }
        }
        public string FileLengthDisplay
        {
            get
            {
#if NO_RESTRICT
                long v = 0;

                if (string.IsNullOrEmpty(FileSize) || (v = long.Parse(this.FileSize)) == 0)
                    return "Not available";
                else if (v > 1024 * 1024 * 1024)
                    return String.Format(CultureInfo.InvariantCulture, "{0:F2} GB", v / (double)(1024 * 1024 * 1024));
                else if (v > 1024 * 1024)
                    return String.Format(CultureInfo.InvariantCulture, "{0:F2} MB", v / (double)(1024 * 1024));
                else
                    return String.Format(CultureInfo.InvariantCulture, "{0:F2} KB", v / (double)(1024));
#else
                return null;
#endif
            }
        }
        public string eMuleHashDisplay
        {
            get
            {
#if NO_RESTRICT
                return eMuleHash;
#else
                return null;
#endif
            }
        }
    }
}